<%@page import="pro.syj.dao.StudentDao"%>
<%@page import="pro.syj.bean.Student"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>学生信息管理</title>
	<link rel='stylesheet' href='CSS/decorator1.css'>
</head>

<body>
	<h1>学生信息管理</h1>
	<hr>
	<%
  		request.setCharacterEncoding("utf-8"); 
  		response.setContentType("text/html;charset=UTF-8");
  	%>
	
	<br>
	<div id="before">
	    <form action="managerQstudent-do.jsp" method="post">
	        请输入学生学号：<input type="text" name="sid" required><input type="submit" value="查询" />
	    </form>
	    <br>
	    <a href="javascript: window.history.go(-1)">返回上一级</a>
	</div>
	
	<br>
  	  	<table align="center" cellspacing="0">
  		 <tr bgcolor="#5f9ea0" style="font-size: 20px;height:40px;text-align: center">
	        <td style="width: 120px">学号</td>
	        <td style="width: 120px">姓名</td>
	        <td style="width: 120px">年级</td>
	        <td style="width: 120px">专业</td>
	        <td style="width: 120px">删除</td>
    	</tr>
  		
  		<%
  			int cutpage = 1;
  			final int cntPrePage = 7;
  			if (request.getParameter("cutpage") != null) {
  				cutpage = Integer.parseInt(request.getParameter("cutpage"));
  			}
  			String[] color = {"pink", "yellow"};
  			
  			StudentDao studentdao = new StudentDao();
  			ArrayList<Student> list = (ArrayList<Student>)request.getAttribute("studentlist");
  			if(list == null || "".equals(list)){
  				list = studentdao.selectAll();
  			}
  			
  			int count = list.size();
  			int prepage = cutpage - 1;
  			int nxtpage = cutpage + 1;
  			if (prepage <= 0) prepage = 1;
  			if (cutpage * cntPrePage >= count) nxtpage = cutpage;
  			
  			
  			if (list != null && list.size() > 0) {
  				for (int i = (cutpage-1)*cntPrePage; i < cutpage*cntPrePage && i < count; i++) {
	  				Student student = list.get(i);
	  	%>
		<tr bgcolor="<%=color[i%2] %>" >
			<td><%=student.getSid() %></td>
			<td><%=student.getSname() %></td>
			<td><%=student.getGrade() %></td>
			<td><%=student.getMajor() %></td>
			<td><a href="managerDstudent.jsp?sid=<%=student.getSid() %>">删除</a></td>
		</tr>
	  			
	  	<%
	  			}
	  		}
  		%>
  		</table>
  		<div>
  		<p><a href="managerQstudent.jsp?cutpage=<%=prepage%>">[上一页]</a>
  			&nbsp;(<%=cutpage %>/<%=(count-1)/cntPrePage+1 %>)&nbsp;
  			<a href="managerQstudent.jsp?cutpage=<%=nxtpage%>">[下一页]</a></p>
  			<a href="managerMain.jsp">[返回主界面]</a>
  	   </div>
</body>
</html>